package cn.itcast.service.impl;

import cn.itcast.dao.InOutStorageRepository;
import cn.itcast.dao.TransitRepository;
import cn.itcast.domain.transit.InOutStorageInfo;
import cn.itcast.domain.transit.TransitInfo;
import cn.itcast.service.InOutStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class InOutStorageServiceImpl implements InOutStorageService {
    @Autowired
    private InOutStorageRepository inOutStorageRepository;
    @Autowired
    private TransitRepository transitRepository;
    @Override
    @Transactional
    public void save(String transitInfoId, InOutStorageInfo inOutStorageInfo) {
        //保存inoutstorageinfo数据
        inOutStorageRepository.save(inOutStorageInfo);
        //查询transitinfo
        TransitInfo transitInfo = transitRepository.findOne(Integer.parseInt(transitInfoId));
        //关联出入库信息到运输配送对象
        transitInfo.getInOutStorageInfos().add(inOutStorageInfo);
        //判断是否到达网点
        if( "到达网点".equals(inOutStorageInfo.getOperation())){

            transitInfo.setStatus("到达网点");
            //更新网点地址 显示配送状态
            transitInfo.setOutletAddress(inOutStorageInfo.getAddress());
        }
    }
}
